package com.selfstudy.controller;


import com.selfstudy.dto.StudentUserLoginDTO;
import com.selfstudy.dto.StudentUserRegisterDTO;
import com.selfstudy.properties.JwtProperties;
import com.selfstudy.result.Result;
import com.selfstudy.service.IStudentUserService;
import com.selfstudy.vo.StudentUserInfoVO;
import com.selfstudy.vo.StudentUserLoginVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.security.auth.login.AccountNotFoundException;

/**
 * <p>
 * 学生用户表 前端控制器
 * </p>
 *
 * @author author
 * @since 2025-04-08
 */
@Api(tags = "学生用户登录")
@RestController
@RequiredArgsConstructor
@RequestMapping("/student-user")
public class StudentUserController {
    private  final IStudentUserService iStudentUserService;
    @ApiOperation("用户登录接口")
    @PostMapping("/login")
    public Result<StudentUserLoginVO> login(@RequestBody @Validated StudentUserLoginDTO studentUserLoginDTO) throws AccountNotFoundException {
        //获取用户登录信息
        StudentUserLoginVO loginVO = iStudentUserService.login(studentUserLoginDTO);
        return Result.success(loginVO);
    }

    @ApiOperation("用户注册接口")
    @PostMapping("/register")
    public Result register(@RequestBody @Validated StudentUserRegisterDTO studentUserRegisterDTO){
        iStudentUserService.register(studentUserRegisterDTO);
        return Result.success();
    }

    @ApiOperation("用户退出登录接口")
    @GetMapping("/logout")
    public Result logout(){
        //TODO 退出登录
        return Result.success("退出登录成功!");
    }

    @ApiOperation("获取用户信息接口")
    @GetMapping("/info/{id}")
    public Result<StudentUserInfoVO> info(@PathVariable("id") Integer id){
        return Result.success(iStudentUserService.info(id));
    }
}
